#define _CRT_SECURE_NO_WARNINGS
#pragma once
#include <iostream>
using namespace std;
#include <vector>
#include <deque>

namespace wmz
{
	template <class T>
	class myless
	{
	public:
		bool operator()(const T& x, const T& y)
		{
			return x < y;
		}
	};
	template <class T>
	class mygreater
	{
	public:
		bool operator()(const T& x, const T& y)
		{
			return x > y;
		}
	};
	template<class T,class Container = vector<T>,class Compare = myless<T>>
	class priority_queue
	{
	public:
		priority_queue() = default;
		template<class InputIterator>
		priority_queue(InputIterator first, InputIterator last)
		{
			while (first != last)
			{
				_con.push_back(*first);
				++first;
			}

			for (int i = (_con.size() - 1) / 2; i >= 0; i--)
				adjust_down(i);
		}
		void adjust_up(int child)
		{
			Compare comfunc;
			int parent = (child - 1) / 2;
			while (parent >= 0)
			{
				if (comfunc(_con[parent], _con[child]))
				{
					swap(_con[parent, _con[child]]);
					child = parent;
					parent = (child - 1) / 2;
				}
				else
				{
					break;
				}
			}
		}
		void push(const T& x)
		{
			_con.push_back(x);
			adjust_up(_con.size() - 1);
		}

		void adjust_down(int parent)
		{
			Compare comfunc;
			size_t child = 2 * parent+1;
			while (child < _con.size())
			{
				if (child + 1 < _con.size() && comfunc(_con[child], _con[child + 1]))
					child++;
				if (comfunc(_con[parent], _con[child]))
				{
					swap(_con[parent], _con[child]);
					parent = child;
					child = 2 * parent+1;
				}
				else
				{
					break;
				}
			}
		}
		void pop()
		{
			swap(_con[0], _con[_con.size() - 1]);
			_con.pop_back();
			adjust_down(0);
		}
		const T& top()
		{
			return _con[0];
		}
		size_t size()
		{
			return _con.size();
		}
		bool empty()
		{
			return _con.empty();
		}
	private:
		Container _con;
	};
}